#pragma once
#include<array>
using namespace std;

#include<ctime>
#include<cstdlib>   //qsort bsearch

#define ASIZE 50000

int CompareLong(void const* a, void const* b) {
    return *(long*)a - *(long*)b;
}

void tTest_Array() {

    array<long, ASIZE> a;

    clock_t timeStart = clock();
    cout << "开始时间: " << timeStart << endl;

    for (long i = 0; i < ASIZE; i++) {
        a[i] = rand();
    }

    cout << "赋值所需要时间: " << clock() - timeStart << endl;
    cout << "数组大小: " << a.size() << endl;
    cout << "数组起点元素: " << a.front() << endl;
    cout << "数组终点元素: " << a.back() << endl;
    cout << "数组起点地址: " << a.data() << endl;

    timeStart = clock();
    //c 标准库, 快速排序
    qsort(a.data(), ASIZE, sizeof(long), CompareLong);
    cout << "排序所需要时间: " << clock() - timeStart << endl;

    timeStart = clock();
    long search;
    cin >> search;
    //二分查找  (先排序)
    long* result = (long*)bsearch(&search, a.data(), ASIZE, sizeof(long), CompareLong);
    cout << "查找所需要时间: " << clock() - timeStart << endl;
    if (result != NULL)
        cout << "查找元素: " << *result << endl;
    else
        cout << "找不到" << endl;
}